using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web.DataHelper
{
	public class HL_NavegateBll
	{
		private Conn conn = null;
		public HL_NavegateBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public HL_NavegateBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetLinksAll(params string[] position)
		{
			string arg = "";
			if (position.Length == 1)
			{
				arg = string.Format(" where Position='{0}'", position[0]);
			}
			string arg2 = "*";
			string sql = string.Format("select ROW_NUMBER() OVER (ORDER BY n.OrderNumber ASC) rowid, {0}  from HL_Navegate n {1} order by n.OrderNumber asc", arg2, arg);
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetLinksAll(int selectCount, params string[] position)
		{
			if (selectCount < 1)
			{
				selectCount = 1;
			}
			string arg = "";
			if (position.Length == 1)
			{
				arg = string.Format(" where Position='{0}'", position[0]);
			}
			string arg2 = "*";
			string sql = string.Format("select top {2} ROW_NUMBER() OVER (ORDER BY n.OrderNumber ASC) rowid, {0}  from HL_Navegate n {1} order by n.OrderNumber asc", arg2, arg, selectCount);
			return this.conn.GetDataTable(sql);
		}
		public bool AddLink(string Title, string Position, string Link, long OrderNumber, string Remark)
		{
			bool result = true;
			string commandText = "INSERT INTO HL_Navegate(Title,Position,Link,OrderNumber,Remark)VALUES(@Title,@Position,@Link,@OrderNumber,@Remark)";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@Title", DbType.String, Title),
				this.conn.CreateParameter("@Position", DbType.String, Position),
				this.conn.CreateParameter("@Link", DbType.String, Link),
				this.conn.CreateParameter("@OrderNumber", DbType.Int64, OrderNumber),
				this.conn.CreateParameter("@Remark", DbType.String, Remark)
			};
			try
			{
				this.conn.Execute(commandText, parameters);
			}
			catch
			{
				result = false;
			}
			return result;
		}
		public bool UpdateLink(long id, string Title, string Position, string Link, long OrderNumber, string Remark)
		{
			bool result = true;
			string commandText = "UPDATE HL_Navegate SET Title=@Title,Position=@Position,Link=@Link,OrderNumber=@OrderNumber,Remark=@Remark where id=@id";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@Title", DbType.String, Title),
				this.conn.CreateParameter("@Position", DbType.String, Position),
				this.conn.CreateParameter("@Link", DbType.String, Link),
				this.conn.CreateParameter("@OrderNumber", DbType.Int64, OrderNumber),
				this.conn.CreateParameter("@Remark", DbType.String, Remark),
				this.conn.CreateParameter("@id", DbType.Int64, id)
			};
			try
			{
				this.conn.Execute(commandText, parameters);
			}
			catch
			{
				result = false;
			}
			return result;
		}
		public bool DeleteLink(long id)
		{
			bool result = true;
			string commandText = "DELETE FROM HL_Navegate WHERE id=@id";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@id", DbType.Int64, id)
			};
			try
			{
				this.conn.Execute(commandText, parameters);
			}
			catch
			{
				result = false;
			}
			return result;
		}
	}
}
